package com.cxy.instarsystem.service;

import com.cxy.instarsystem.dao.UserRepository;
import com.cxy.instarsystem.po.User;
import com.cxy.instarsystem.util.MD5Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class UserServiceImpl implements UserService{
    @Autowired
    private UserRepository userRepository;
    @Override
    public void saveRegister(User user) {
        String pwd = MD5Utils.code(user.getPassword());
        user.setPassword(pwd);
        user.setCreateTime(new Date());
        user.setUpdateTime(new Date());
        System.out.println(user.getNickname());
        userRepository.save(user);
    }

    @Override
    public Boolean isUsernameRepeat(String username) {
        User user = userRepository.findByUsername(username);
        return user == null;
    }

    @Override
    public User checkUser(String username, String password) {
        return userRepository.findByUsernameAndPassword(username, MD5Utils.code(password));
    }
}
